﻿using Microsoft.Practices.Unity;
using RockBus.Initialization.Interfaces;
using RockBus.Routing;
using RockBus.Routing.Interfaces;
using RockBus.MessageProcessors.SendPorts;
using RockBus.MessageProcessors.MessageRepository;

namespace RockBus.Composition
{
    public class DbSubscriptionPersistenceDbMessagePersistenceDependencyManager : DependencyManagerBase
    {
        protected override void FillContainer(IUnityContainer container)
        {
            this.FillContainerWithSqlServerConfigurationRespository(container);
            this.FillContainerWithSqlServerMessageRepository(container);

            container
            .RegisterType<IMessageRepositoryHelper, MessageRepositoryHelper>(new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, MessageProcessor>(InstanceNames.PersistenceSendPort, new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, DeliverySendPort>(InstanceNames.DeliverySendPort, new ContainerControlledLifetimeManager())
            .RegisterType<IMessageProcessor, ErrorProcessor>(InstanceNames.ErrorManager, new ContainerControlledLifetimeManager())

            // PublisherManager dependencies
            .RegisterType<IMessagePublisher, MessagePublisher>(InstanceNames.DbMessagePublisher, new ContainerControlledLifetimeManager())
            .RegisterType<IPublisherManager, PublisherManager>(new ContainerControlledLifetimeManager())
            .RegisterType<IInitialization, PublisherManagerInitialization>(InstanceNames.PublisherManagerInitialization, new ContainerControlledLifetimeManager())
            ;
        }
    }
}